package com.baizhi.wwx.controller;

import com.baizhi.wwx.dto.QueryPageDTO;
import com.baizhi.wwx.entity.Category;
import com.baizhi.wwx.service.CategoryService;
import com.baizhi.wwx.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("category")
@CrossOrigin
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @RequestMapping("queryOnePage")
    @ResponseBody
    public CategoryVo queryOnePage(@RequestBody QueryPageDTO queryPageDTO){
        return categoryService.queryOnePage(queryPageDTO.getPage(), queryPageDTO.getPageSize());
    }
    @RequestMapping("queryTwoPage")
    @ResponseBody
    public CategoryVo queryTwoPage(@RequestBody QueryPageDTO queryPageDTO){
        return categoryService.queryTwoPage(queryPageDTO.getPage(), queryPageDTO.getPageSize(), queryPageDTO.getCategoryId());
    }
    @RequestMapping("queryById")
    @ResponseBody
    public Category queryById(Integer id){
        return categoryService.queryById(id);
    }
    @RequestMapping("queryByLevelsCategory")
    @ResponseBody
    public List<Category> queryByLevelsCategory(Integer levels){
        return categoryService.queryByLevelsCategory(levels);
    }
    @RequestMapping("add")
    @ResponseBody
    public Map<String,Object>add(@RequestBody Category category){
        return categoryService.add(category.getCateName(),category.getParentId());
    }
    @RequestMapping("update")
    @ResponseBody
    public Map<String ,Object>update(@RequestBody Category category){
        return categoryService.update(category.getId(),category.getCateName(),category.getParentId());
    }
    @RequestMapping("delete")
    @ResponseBody
    public Map<String,Object>delete(@RequestBody Category category){
        return categoryService.delete(category.getId(),category.getParentId());
    }

}
